//        https://www.nowcoder.com/questionTerminal/90d6a362fa7d4c519d557da797bb02ce?answerType=1&f=discussion




#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

int main()
{
    string s;
    cin >> s;

    int n = s.size();
    if (n <= 2)
    {
        cout << n << endl;
        return 0;
    }

    unordered_map<char, int> m;
    int l = 0, r = 0, len = 0;
    int cnt = 0;

    while (r < n)
    {
        if (m[s[r]] == 0)
            cnt++;
        m[s[r++]]++;
        while (cnt > 2)
        {
            m[s[l]]--;
            if (m[s[l++]] == 0)
                cnt--;
        }
        len = max(len, r - l);
    }

    cout << len << endl;
    return 0;
}